<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 作业：封装函数 处理'ababfasbasfbfdbfbafbafb' // 出现最多的符号，次数为几
      const arr = 'ababfasbasfbfdbfbafbafb'
      // console.log(arr)
      let arr1 = arr.split('')
      // console.log(arr1);
      let mgcs = {}
      function add() {
        let a = 0
        let b = 0
        for (let k in arr1) {
          mgcs[1] = 'a'
          if (mgcs[arr1[k]]) {
            mgcs[arr1[k]]++
          } else {
            mgcs[arr1[k]] = 1
          }
          if (mgcs[arr1[k]] > a) {
            a = mgcs[arr1[k]]
            b = arr1[k]
          }
        }
        // console.log(mgcs);
        // console.log(a)
        // console.log(b)
        return `出现最多的是${b}，次数为${a}`
      }
      console.log(add()); 
    </script>
  </body>
</html>
